package com.eeepay.eeepay_v2._recadapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.eeepay.eeepay_v2.R;

import cn.eeepay.api.grpc.nano.ManagementCenterProto;

/**
 * 描述：超级推收益的适配器
 * 作者：zhuangzeqin
 * 时间: 2017/7/24-14:49
 * 邮箱：zzq@eeepay.cn
 */
public class CJTInComeInfoListAdapter extends CommRecyclerBaseAdater<ManagementCenterProto.SuperPushShareRecord> {
    public CJTInComeInfoListAdapter(@NonNull Context mContext) {
        super(mContext);
    }

    @Override
    public int getViewType(int position) {
        return 0;
    }

    @Override
    public int getItemLayoutId(int ViewType) {
        return R.layout.item_cjtinfo_list;
    }

    @Override
    public void onBindView(CommonViewHolder holder, ManagementCenterProto.SuperPushShareRecord model, int position, int viewType) {
        if (model == null) return;
        holder.setText(R.id.tv_amountValue, model.transAmount);//交易金额
        String mobilePhone = model.mobile;
        if (!TextUtils.isEmpty(mobilePhone) && mobilePhone.length()>=11)
        {
            mobilePhone= mobilePhone.replaceAll("(\\d{3})\\d{4}(\\d{4})", "$1****$2");
        }
        holder.setText(R.id.tv_transactionPhone, mobilePhone);//交易手机号
        holder.setText(R.id.tv_transactionTime, model.createTime);//创建时间
        holder.setText(R.id.tv_InCome, "￥"+model.shareAmount);//入账金额or贡献金额
        TextView transactionstate = (TextView) holder.getItemView().findViewById(R.id.tv_transactionstate);//收益状态
        TextView tv_tv_transactionInCome = (TextView) holder.getItemView().findViewById(R.id.tv_tv_transactionInCome);//贡献收益 或者 已入账
        String share_state = model.shareStatus;//分润入账状态,0 未入账, 1 已入账,2 入账失败
        if (share_state.equals("0"))//1 对于未入账的收益，其后的标注是待入账
        {
            transactionstate.setBackgroundResource(R.drawable.drz);
            transactionstate.setText("待入账");
            transactionstate.setTextColor(mContext.getResources().getColor(R.color.unify_grounding_white));
        }
        else if (share_state.equals("2"))//入账失败
        {
            transactionstate.setBackgroundResource(R.drawable.ygb);
            transactionstate.setText("入账失败");
            transactionstate.setTextColor(mContext.getResources().getColor(R.color.unify_grounding_white));
        }
        else {
            if (share_state.equals("1"))//2 入账,对于入账状态是已入账的，则将贡献收益改为已入账
            {
                tv_tv_transactionInCome.setText("已入账:");
                transactionstate.setVisibility(View.GONE);//隐藏掉标注
            } else {
                tv_tv_transactionInCome.setText("贡献收益:");
                transactionstate.setVisibility(View.VISIBLE);//显示标注
            }
        }
    }
}
